1 module unde.games.dizzy.omega.animations.stone_01;
2 
3 import derelict.opengl3.gl;
4 import std.conv;
5 import std.math;
6 import std.stdio;
7 import unde.games.object;
8 import unde.games.renderer;
9 import unde.global_state;
10 
11 class Stone01:StaticGameObject
12 {    
13     StaticGameObject the_hero;
14 
15     this(MainGameObject root, StaticGameObject hero)
16     {
17         frame = -1;
18         the_hero = hero;
19 
20         models["stone-01"] = root.models["stone-01"];
21         super(root);
22     }
23 
24     override void draw(GlobalState gs)
25     {
26         if (abs(root.scrx-20.6) > 16.0 ||
27             abs(root.scry-0.0) > 9.0) return;
28             
29         float f = 0.0;   
30         if (frame >= 0.0)
31         {
32             f = root.frame - frame;
33         }
34         
35         glPushMatrix();
36         if (f <= 0.0)
37         {
38             glTranslatef(20.6, 4.5, 2.0);
39         }
40         else if (f < 200.0)
41         {
42             glTranslatef(20.6 + (25.1-20.6)*f/200.0, 4.5 - (4.5-1.9)*f/200.0, 2.0);
43             glRotatef(-228.0*f/200.0, 0.0, 0.0, 1.0);
44         }
45         else if (f < 250.0)
46         {
47             glTranslatef(25.1 + (25.2-25.1)*(f-200.0)/50.0, 1.9 - (1.9-0.05)*(f-200.0)/50.0, 2.0);
48             glRotatef(-228.0-(263.0-228.0)*(f-200.0)/50.0, 0.0, 0.0, 1.0);
49         }
50         else
51         {
52             glTranslatef(25.2, 0.05, 2.0);
53             glRotatef(-263.0, 0.0, 0.0, 1.0);
54         }
55         recursive_render(gs, models["stone-01"]);
56         glPopMatrix();
57     }
58 
59     override bool tick(GlobalState gs)
60     {
61         if (frame < 0 && the_hero.x > 34.6)
62         {
63             frame = root.frame;
64         }        
65         return true;
66     }
67 
68     override void load(string[string] s)
69     {
70         if ("stone-01-frame" in s)
71             frame = s["stone-01-frame"].to!(long);
72         else
73             frame = -1;
74     }
75 
76     override void save(ref string[string] s)
77     {
78         if (frame >= 0)
79             s["stone-01-frame"] = frame.to!(string);
80     }    
81 }